<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>自动完成</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="${base}/scripts/common/core.js"></script>
<script type="text/javascript"
	src="${base}/scripts/plugin/jquery.min.js"></script>
<script type="text/javascript" src="${base}/scripts/common/InitArtDialog.js"></script>
<script src="${base}/scripts/plugin/artDialog/plugins/iframeTools.source.js"></script>
<style>body{height:auto}</style>
</head>
<body>
	<table style="margin: 10px;">
		<tr>
		<td align="left">
				<div style="width: 720px; height: 450px; border: 1px solid gray;"
				id="map"></div>
			</td>
		</tr>
	</table>
	<script type="text/javascript">
				var type="${type!''}";
				var myIcon = new BMap.Icon("${base}/images/baidu_blue.png", new BMap.Size(22,24));
				var map = new BMap.Map("map");
				var p="${point!''}";
				var point;
				//添加标注
				var myMark=null;
				var p1;
				if(p!='' && p!='0,0'){
					p1=p.split(",");
					point = new BMap.Point(p1[0], p1[1]);
					map.clearOverlays();
					map.centerAndZoom(point, 18);
					myMark= new BMap.Marker(point,{icon:myIcon});
					map.addOverlay(myMark); //添加标注
					//myMark.enableDragging();    
				}else{
					map.centerAndZoom("${city}", 12);
				}
				map.enableScrollWheelZoom();
				map.addControl(new BMap.NavigationControl());
				map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]})); 
				//map.addControl(new BMap.MapTypeControl({anchor: BMAP_NAVIGATION_CONTROL_SMALL})); 
				var ac = new BMap.Autocomplete( //建立一个自动完成的对象
				{
					"input" : "suggestId",
					"location" :"${city}"
				});

				ac.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
					var str = "";
					var _value = e.fromitem.value;
					var value = "";
					if (e.fromitem.index > -1) {
						value = _value.province + _value.city + _value.district
								+ _value.street + _value.business;
					}
					str = "FromItem<br />index = " + e.fromitem.index
							+ "<br />value = " + value;

					value = "";
					if (e.toitem.index > -1) {
						_value = e.toitem.value;
						value = _value.province + _value.city + _value.district
								+ _value.street + _value.business;
					}
					str += "<br />ToItem<br />index = " + e.toitem.index
							+ "<br />value = " + value;
				});

				var myValue;
				ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
					var _value = e.item.value;
					myValue = _value.province + _value.city + _value.district
							+ _value.street + _value.business;
					setPlace();
				});

				function G(id) {
					return document.getElementById(id);
				}
				
				var local = new BMap.LocalSearch(map, { //智能搜索
					onSearchComplete : myFun,
					renderOptions:{map: map}
				});
				$("#btnSearch").bind("click",function(){
					local.search($("#suggestId").val());
				});
				function myFun() {
					// var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
					map.clearOverlays(); //清除地图上所有覆盖物
				}
				map.addEventListener("dragend", function showInfo(){
					});
				function setPlace() {
					map.clearOverlays(); //清除地图上所有覆盖物
					local.search(myValue);
				/* 	if(type!=''){
						local.search(myValue);
						
					}else{
						local.searchNearby("公交车站",myValue);
					} */
				}
	//得到标注坐标
	function getPoint(){
		var point="";
		if(myMark !=null){
			point = myMark.getPosition().lng +","+myMark.getPosition().lat;
		}
		art.dialog.data("point",point);
		art.dialog.close();
	}
	function addMark(){
		map.removeOverlay(myMark);
		myMark = new BMap.Marker(map.getCenter(),{icon:myIcon});
		map.addOverlay(myMark); //添加标注
		myMark.enableDragging();    
	}
	//移除标注
	function deleteMark(){
		map.removeOverlay(myMark);
		myMark = null;
	}
</script>
</body>
</html>
